package cn.zhizihua.service.impl;

import cn.zhizihua.mapper.DepartmentMapper;
import cn.zhizihua.pojo.Department;
import cn.zhizihua.service.IDepartmentService;
import cn.zhizihua.vo.ResultBean;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhizihua
 * @since 2024-12-18
 */
@Service
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements IDepartmentService {

    @Autowired
    DepartmentMapper departmentMapper;
    @Override
    public ResultBean getDeptNames() {
        // 查询
        List<Department> allDeptName = departmentMapper.getAllDeptName();

        //数组接收查到的dept_name
        ArrayList<Object> list = new ArrayList<>();
        for (Department department : allDeptName) {
            list.add(department);
        }

        //转为json
        String json = JSON.toJSONString(list);

        return ResultBean.SUCCESS(json);
    }
}
